/*
 * jxSwing Project (2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxSwing.component.table.cellEditor;

import javax.swing.DefaultCellEditor;

import org.jxSwing.component.comboBox.YesNoComboBox;
import org.jxSwing.i18n.I18N;
import org.jxUtils.check.CheckUtil;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxSwing
 * @package org.jxSwing.component.table.cellEditor
 * @date 12/09/2014 - 18:45:18
 */
public class YesNoEditor extends DefaultCellEditor {
	
	private static final long serialVersionUID = -5045329657941501835L;
	
	/**
	 * 
	 */
	public YesNoEditor() {
	
		super(new YesNoComboBox());
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.DefaultCellEditor#getCellEditorValue()
	 */
	@Override
	public Boolean getCellEditorValue() {
	
		final String value = getComponent().getSelectedItem();
		
		return CheckUtil.isNullOrAbsoluteEmpty(value) ? null : value.endsWith(I18N.component().yes());
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.DefaultCellEditor#getComponent()
	 */
	@Override
	public YesNoComboBox getComponent() {
	
		return (YesNoComboBox)super.getComponent();
	}
}
